home *** CD-ROM | disk | FTP | other *** search
/ SGI ONC3 NFS v2 / SGI ONC3 NFS v2.iso / dist6.3 / nfs.idb / var / yp / ypmake.z / ypmake
Text File  |  1996-11-21  |  2KB  |  65 lines

  1. #!/bin/sh
  2. # NAME
  3. #    ypmake - NIS master script to update databases and to rotate logfiles
  4. # SYNOPSIS
  5. #    /var/yp/ypmake
  6. # DESCRIPTION
  7. #    ypmake is run on NIS master servers by cron(1M) to ensure that their 
  8. #    NIS databases are up-to-date and pushed out to slave servers.
  9. #
  10. #    You can also use this script to push a map after updating its 
  11. #    data file. Any output from the make is printed on the standard output.
  12. #
  13. #    An optional configuration file, /etc/config/ypmaster.options,
  14. #    lets you customize the variables used by make when it creates
  15. #    the NIS databases. See ypmake(1) for details.
  16.  
  17. cd /var/yp
  18.  
  19. LOG=ypmake.log
  20.  
  21. test -t 0
  22. interactive=$?
  23.  
  24. # Keep the log file open during all actions for fuser test
  25. touch $LOG
  26. exec < $LOG
  27.  
  28. # Make sure another ypmake isn't running already.  Do an echo after fuser output
  29. # because sed doesn't always work correctly without a newline
  30. pids="`(/sbin/fuser -q $LOG $LOG.old; echo '') < /dev/null | sed -e s/$$,*//g -e 's/,*$//'`"
  31.  
  32. if test -n "$pids"; then
  33.     err="already in use by processes $pids"
  34.     if  test $interactive = 0; then
  35.         echo "ypmake: $err"
  36.     else
  37.         logger -t ypmake -p daemon.warning "$err"    # log it in SYSLOG
  38.     fi
  39.     exit 1
  40. fi
  41.  
  42. if test $interactive = 1; then        # not interactive
  43.     if /etc/chkconfig ypmaster; then :
  44.     else
  45.         exit 0
  46.     fi
  47.     PATH=$PATH:`dirname $0`
  48.     exec >> $LOG 2>&1
  49.  
  50.     # Between 12:00am and 12:14am, redo the maps if they haven't been
  51.     # made in the past day.
  52.     if test `date +%H%M` -le 14; then
  53.         if test -n "`find . -name '*.time' -mtime +0 \
  54.                 -type f -print 2>/dev/null`"; then
  55.             rm -f *.time
  56.         fi
  57.         mv -f $LOG $LOG.old
  58.         exec >> $LOG 2>&1
  59.         date
  60.     fi
  61. fi
  62.  
  63. /usr/sbin/ypset `hostname` 2>/dev/null
  64. make -ksf make.script `cat /etc/config/ypmaster.options 2>/dev/null` $*
  65.